package org.CurrencyDAO.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity
@NamedQueries({
    @NamedQuery(name = "CurrencyExchange.poId", query = "SELECT o FROM CurrencyExchange o WHERE o.id = :id"),
    @NamedQuery(name = "CurrencyExchange.wszystko", query = "SELECT o FROM CurrencyExchange o"),
    @NamedQuery(name = "CurrencyExchange.poIdJOIN_FETCH", query = "SELECT o FROM CurrencyExchange o  JOIN FETCH o.currency WHERE o.id = :id"),
    @NamedQuery(name = "CurrencyExchange.poIdLEFT_JOIN_FETCH", query = "SELECT o FROM CurrencyExchange o LEFT JOIN o.currency WHERE o.id = :id")
})
@Table(name = "currency_exchange")
public class CurrencyExchange implements Serializable {

	private static final long serialVersionUID = -757642068382659564L;

	@Id
	@Column(name = "id", columnDefinition = "serial")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

//	@ManyToOne(fetch = FetchType.EAGER)
//	@Cascade(CascadeType.PERSIST)
	@ManyToOne(cascade=javax.persistence.CascadeType.PERSIST, fetch=FetchType.LAZY)
	@JoinColumn(name = "id_currency")
	private Currency currency;

	@Column(name = "public_date")
	@Temporal(TemporalType.DATE)
	private Date date;

	@Column(name = "converter")
	private Integer converter;

	@Column(name = "exchange")
	private BigDecimal averageExchange;

	public Long getId() {
		return id;
		
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Integer getConverter() {
		return converter;
	}

	public void setConverter(Integer converter) {
		this.converter = converter;
	}

	public BigDecimal getAverageExchange() {
		return averageExchange;
	}

	public void setAverageExchange(BigDecimal averageExchange) {
		this.averageExchange = averageExchange;
	}
	
	public Currency getCurrency() {
		return currency;
	}
	
	public void setCurrency(Currency currency) {
		this.currency = currency;
	}

	@Override
	public String toString() {
		return "CurrencyExchange [id=" + id + ", currency=" + currency + ", date=" + date + ", converter=" + converter + ", averageExchange="
				+ averageExchange + "]";
	} 
	

}
